package com.atguigu.jxc.controller;


import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.domain.SuccessCode;
import com.atguigu.jxc.entity.Customer;
import com.atguigu.jxc.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @description 客户管理Controller层
 */
@RestController
@RequestMapping("/customer")
public class CustomerController {

    @Autowired
    private CustomerService customerService;

    //客户列表分页（名称模糊查询）
    @PostMapping("list")
    public Map<String,Object> list(Integer page, Integer rows, String  customerName){
        Map<String,Object> map = customerService.list(page,rows,customerName);
        return map;
    }

    //客户添加或修改
    @PostMapping("save")
    public ServiceVO saveAndUpdate(Customer customer,Integer customerId){
        customerService.saveAndUpdate(customer, customerId);
        return new ServiceVO(SuccessCode.SUCCESS_CODE, SuccessCode.SUCCESS_MESS, null);
    }

    //客户删除（支持批量删除）
    @PostMapping("delete")
    public ServiceVO delete(String  ids){
        customerService.delete(ids);
        return new ServiceVO(SuccessCode.SUCCESS_CODE, SuccessCode.SUCCESS_MESS, null);
    }

}
